#!/bin/sh
#
# Start/stop BeGPIO daemon
#

DAEMON=/usr/local/sbin/begpiod

case "$1" in
  start)
	echo -n "Starting BeGPIO daemon: "
	${DAEMON} -d /etc/begpiod.conf > /dev/null 2>&1
	if [ ${?} -eq 0 ]; then
	  echo "OK"
	else
	  echo "ERROR"
	fi
	;;
  stop)
	echo -n "Stopping BeGPIO daemon: "
	${DAEMON} -k > /dev/null 2>&1
	if [ ${?} -eq 0 ]; then
	  echo "OK"
	else
	  echo "ERROR"
	fi
	;;
  restart)
	${0} stop
	sleep 1 # Prevent race condition: ensure BeGPIO daemon stops before start.
	${0} start
	;;
  *)
	echo "Usage: ${0} {start|stop|restart}"
	exit 1
esac
